M=require("ming_node");
/**
 * serialport@10.4.0
 */
const { SerialPort } = require('serialport')


class MingSericalLcd {


    static isNodeExecute =false;

    static messageEvent=(m)=>{return 0}

    constructor({com,brand,messageEvent,isNodeExecute}) {
        this.sp = new SerialPort({ path: com, baudRate: brand });
        console.log(`connect ${com} ${brand}`)
        MingSericalLcd.messageEvent=messageEvent;
        MingSericalLcd.isNodeExecute=isNodeExecute;
        this.init();
    }

    install(app,args){

    }

    usartSend(m){
        this.sp.write(m);
    }


    init(){
       this.sp.on('readable', async () => {
           await M.delayMs(5);
           let reqBuffer=  this.sp.read();
           MingSericalLcd.messageEvent(reqBuffer.toString());
        });
    }

}

module.exports = MingSericalLcd;